import adminRequest from "@/utils/http/adminRequest.js";

// 分页查询
export const publisherListAPI = (params) => {
    return adminRequest.get('game/admin/publisher/page', {
        params
    })
}

// 新增发行商
export const publisherAddAPI = (publisherInfo, imageFile) => {
    const formData = new FormData();
    formData.append('publisherInfo', JSON.stringify(publisherInfo));
    // 只有当imageFile存在且是文件类型时，才附加到表单数据
    if (imageFile && imageFile instanceof File) {
        formData.append('image', imageFile);
    }
    return adminRequest.post('game/admin/publisher', formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 批量删除
export const publisherDeleteAPI = (ids) => {
    return adminRequest.delete('game/admin/publisher', {
        data: ids
    })
}

// 修改发行商
export const publisherEditAPI = (publisherInfo, imageFile) => {
    const formData = new FormData();
    formData.append('publisherInfo', JSON.stringify(publisherInfo));
    // 只有当imageFile存在且是文件类型时，才附加到表单数据
    if (imageFile && imageFile instanceof File) {
        formData.append('image', imageFile);
    }
    return adminRequest.put('game/admin/publisher', formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 查询发行商
export const publisherGetAPI = (id) => {
    return adminRequest.get(`game/admin/publisher/${id}`)
}

// 查询所有发行商
export const publisherGetAllAPI = (name) => {
    return adminRequest.get('game/publishers', {
        params: {name}
    })
}
